/*
 * @Description:
 * @Author: wangqi
 * @Date: 2024-08-30 18:21:50
 * @LastEditTime: 2024-09-09 11:39:29
 * @LastEditAuthor: wangqi
 */
import {
  Controller,
  Get,
  Post,
  Body,
  Param,
  Delete,
  Logger,
  Query,
  Req,
} from '@nestjs/common';
import { UserService } from './user.service';
import { UserTestService } from './user.test';
import { ConfigService } from '@nestjs/config';
import { User } from 'src/entities/user';

@Controller('user')
export class UserController {
  private logger = new Logger('user控制器:');
  constructor(
    private readonly userService: UserService,
    private configService: ConfigService,
    private userTestService: UserTestService,
  ) {}

  @Post()
  async addUser(@Body() user: User) {
    const userData = await this.userService.findAll();
    user.id = userData.length ? userData.length + 1 : 1;
    this.userService.create(user);
    const result = {
      status: 200,
      code: 0,
    };
    return result;
  }

  @Get()
  findUser() {
    this.logger.warn('=> 来自nestjs/common 的logger');
    return this.userService.findAll();
  }

  @Get(':username')
  findUserByname(@Param('username') username: string) {
    return this.userService.find(username);
  }

  @Get('/info/des/:id')
  findUserInfo(
    @Param('id') id: string,
    @Query() query: any,
    @Req() req: Request,
  ) {
    this.logger.log(id, query.age, req, '参数');
    console.log(1212, 'xx');
    return [1, 2, 3];
  }

  @Post('/setPasswod')
  async update(@Body() user: User) {
    return this.userService.update(user.id, user);
  }

  @Delete(':id')
  remove(@Param('id') id: string) {
    return this.userService.remove(+id);
  }

  @Post('/profile')
  findProfileByUserId(@Body('id') id: number) {
    return this.userService.findProfile(id);
  }
}
